package cn.wei.sdd.core.controller.admin;



import cn.wei.common.exception.Assert;
import cn.wei.common.result.R;
import cn.wei.common.result.ResponseEnum;
import cn.wei.sdd.base.util.JwtUtils;
import cn.wei.sdd.core.enums.TakeMoneyStatusEnum;
import cn.wei.sdd.core.pojo.entity.TakeMoneyRecord;
import cn.wei.sdd.core.pojo.entity.User;
import cn.wei.sdd.core.pojo.query.TakeMoneyQuery;
import cn.wei.sdd.core.pojo.vo.CheckTakeMoneyVO;
import cn.wei.sdd.core.service.TakeMoneyRecordService;
import cn.wei.sdd.core.service.UserAccountService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;


/**
 * <p>
 * 提现记录表 前端控制器
 * </p>
 *
 * @author Wei
 * @since 2021-11-10
 */
@Api(tags = "用户提现管理")
@RestController
@RequestMapping("/admin/core/takeMoneyRecord")
public class AdminTakeMoneyRecordController {

    @Resource
    private TakeMoneyRecordService takeMoneyRecordService;

    @Resource
    private UserAccountService userAccountService;

    @ApiOperation("获取提现列表")
    @GetMapping("getTakeMoneyList/{page}/{limit}")
    public R getTakeMoneyList(

            @ApiParam(value = "当前页码",required = true)
            @PathVariable("page") Long page,
            @ApiParam(value = "页码记录数",required = true)
            @PathVariable("limit") Long limit,
            @ApiParam(value = "查询对象",required = false)
                    TakeMoneyQuery takeMoneyQuery){
        Page<TakeMoneyRecord> pageParam = new Page<>(page, limit);
        IPage<TakeMoneyRecord> pageModel =takeMoneyRecordService.listPage(pageParam,takeMoneyQuery);

        return R.ok().data("pageModel",pageModel);

    }

    @ApiOperation("提现申请审核")
    @GetMapping("examine")
    public R examineTakeMoney(
            @ApiParam(value = "用户提现对象",required = true)
                    CheckTakeMoneyVO checkTakeMoneyVO,
            HttpServletRequest request){
        String token = request.getHeader("token");
        String userName = JwtUtils.getUserName(token);
        String outTradeNo = checkTakeMoneyVO.getOutTradeNo();
        Assert.notEmpty(outTradeNo, ResponseEnum.OUT_TRADE_NO_ERROR);

        Integer status = checkTakeMoneyVO.getStatus();

        takeMoneyRecordService.examineTakeMoney(checkTakeMoneyVO,userName);
        return R.ok();

    }

}

